// src/services/AuthService.js
import BaseService from "./BaseService";
import { 
    setAccountCache, 
    setPasswordCache, 
    setTokenCache 
  } from "./storage";

class AuthService extends BaseService {
  async login(params) {
    const result = await this.request(
      process.env.REACT_APP_API_LOGIN,
      'POST',
      params
    );

    if (result.success && result.data) {
      const token = result.data.token || "";
      if (token) {
        setAccountCache(params.username);
        setPasswordCache(params.password);
        setTokenCache(token);
      }
    }

    return result;
  }
}

export const authService = new AuthService();